<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- 下拉框 -->
<link rel="stylesheet" href="<%=basePath%>statics/ace/css/chosen.css" />
<!-- jsp文件头和头部 -->
<%@ include file="../index/top.jsp"%>
<!-- 日期框 -->
<link rel="stylesheet" href="<%=basePath%>statics/ace/css/datepicker.css" />
</head>
<body class="no-skin">

	<!-- /section:basics/navbar.layout -->
	<div class="main-container" id="main-container">
		<!-- /section:basics/sidebar -->
		<div class="main-content">
			<div class="main-content-inner">
				<div class="page-content">
					<div class="row">
						<div class="col-xs-12">
						
						<!-- 检索  -->
						<form action="<%=basePath%>${baseInfo.moduleName!''}/${baseInfo.objectName!''}/page/listPagination" method="post" name="searchForm" id="searchForm">
						<table style="margin-top:5px;">
							<tr>
								<td>
									<div class="nav-search">
									<!-- 代码生成后需要修改查询参数 -->
									<#list baseInfo.listSearchPropertyInfo as pi>
									<span class="input-icon">
										<input class="nav-search-input" autocomplete="off" id="${pi.propertyName!''}" type="text" name="${pi.propertyName!''}" value="${r"${paramsMap."}${pi.propertyName!''}${r"}"}" placeholder="${pi.remarks!''}" />
										<i class="ace-icon fa fa-search nav-search-icon"></i>
									</span>
									</#list>
									</div>
								</td>
								<td style="padding-left:2px;"><input class="span10 date-picker" name="startTime" value="${r"${paramsMap.startTime}"}" type="text" data-date-format="yyyy-mm-dd" readonly="readonly" style="width:88px;" placeholder="开始时间" title="开始时间"/></td>
								<td style="padding-left:2px;"><input class="span10 date-picker" name="endTime"  value="${r"${paramsMap.endTime}"}" type="text" data-date-format="yyyy-mm-dd" readonly="readonly" style="width:88px;" placeholder="结束时间" title="结束时间"/></td>
								<#list baseInfo.listSelectPropertyInfo as pi>
									<td>${pi.remarks!''}:</td>
									<td style="vertical-align:top;padding-left:2px;">
									 	<select class="chosen-select form-control" name="${pi.propertyName!''}" id="${pi.propertyName!''}" placeholder="请选择${pi.remarks!''}" style="vertical-align:top;width: 120px;">
										<option value="">全部</option>
										<c:forEach items="${r"${listSmDict"}${pi.propertyName?cap_first}${r"}"}" var="dict">
											<option value="${r"${dict.dictCode }"}" <c:if test="${r"${paramsMap."}${pi.propertyName!''}${r"==dict.dictCode}"}">selected</c:if>>${r"${dict.dictName }"}</option>
										</c:forEach>
									  	</select>
									</td>
								</#list>
								<td style="vertical-align:top;padding-left:2px;"><a class="btn btn-light btn-xs" onclick="searchs();"  title="检索"><i  class="ace-icon fa fa-search bigger-110 nav-search-icon blue"></i></a></td>
								<td style="vertical-align:top;padding-left:2px;"><a class="btn btn-light btn-xs" onclick="resets();"  title="重置"><i  class="ace-icon fa fa-reply bigger-110 nav-search-icon blue"></i></a></td>
								<td style="vertical-align:top;padding-left:2px;"><a class="btn btn-light btn-xs" onclick="toExcel();" title="导出到EXCEL"><i  class="ace-icon fa fa-download bigger-110 nav-search-icon blue"></i></a></td>
								<!-- <td style="vertical-align:top;padding-left:2px;"><a class="btn btn-light btn-xs" onclick="fromExcel();" title="从EXCEL导入"><i  class="ace-icon fa fa-cloud-upload bigger-110 nav-search-icon blue"></i></a></td> -->
							</tr>
						</table>
						<!-- 检索  -->
					
						<table id="simple-table" class="table table-striped table-bordered table-hover"  style="margin-top:5px;">
							<thead>
								<tr>
									<th class="center" style="width:35px;">
									<label class="pos-rel"><input type="checkbox" class="ace" id="zcheckbox" /><span class="lbl"></span></label>
									</th>
									<#list baseInfo.propertyInfos as pi>
									<th class="center">${pi.remarks!''}</th>
									</#list>
									<#list baseInfo.listSelectPropertyInfo as pi>
									<th class="center">${pi.remarks!''}</th>
									</#list>
									<th class="center">操作</th>
								</tr>
							</thead>
													
							<tbody>
								
							<!-- 开始循环-->	
							<c:choose>
								<c:when test="${r"${not empty pageDto.list}"}">
									<c:forEach items="${r"${pageDto.list}"}" var="obj" varStatus="vs">
												
										<tr>
											<td class='center' style="width: 30px;">
												<label><input type='checkbox' name='ids' value="${r"${obj."}${baseInfo.primaryKeyProperty!''}${r"}"}" class="ace"/><span class="lbl"></span></label>
											</td>
											<#list baseInfo.propertyInfos as pi>
											<td class="center">${r"${obj."}${pi.propertyName!''}${r"}"}</td>
											</#list>
											<#list baseInfo.listSelectPropertyInfo as pi>
											<td class="center">${r"${obj."}${pi.propertyName!''}Name${r"}"}</td>
											</#list>
											<td class="center">
												<div class="hidden-sm hidden-xs btn-group">
												    <a class="btn btn-xs btn-success" title="查看" onclick="viewObj('${r"${obj."}${baseInfo.primaryKeyProperty!''}${r"}"}');return false;">
														<i class="ace-icon fa fa-bookmark bigger-120" title="查看"></i>
													</a>
													<a class="btn btn-xs btn-success" title="编辑" onclick="editObj('${r"${obj."}${baseInfo.primaryKeyProperty!''}${r"}"}');return false;">
														<i class="ace-icon fa fa-pencil-square-o bigger-120" title="编辑"></i>
													</a>
													<a class="btn btn-xs btn-danger" onclick="delObj('${r"${obj."}${baseInfo.primaryKeyProperty!''}${r"}"}','');return false;">
														<i class="ace-icon fa fa-trash-o bigger-120" title="删除"></i>
													</a>
												</div>
											</td>
										</tr>
									</c:forEach>
								</c:when>
								<c:otherwise>
									<tr class="main_info">
										<td colspan="10" class="center">没有相关数据</td>
									</tr>
								</c:otherwise>
							</c:choose>
							</tbody>
						</table>
						
					<div class="page-header position-relative">
					<table style="width:100%;">
						<tr>
							<td style="vertical-align:top;">
								<a class="btn btn-mini btn-success" onclick="add();">新增</a>
								<a title="批量删除" class="btn btn-mini btn-danger" onclick="makeAll();" ><i class='ace-icon fa fa-trash-o bigger-120'></i></a>
							</td>
							<td style="vertical-align:top;"><div class="pagination" style="float: right;padding-top: 0px;margin-top: 0px;">${r"${pageDto.pageStr}"}</div></td>
						</tr>
					</table>
					</div>
					</form>
						</div>
						<!-- /.col -->
					</div>
					<!-- /.row -->
				</div>
				<!-- /.page-content -->
			</div>
		</div>
		<!-- /.main-content -->

		<!-- 返回顶部 -->
		<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
			<i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
		</a>

	</div>
	<!-- /.main-container -->

	<!-- basic scripts -->
	<!-- 页面底部js¨ -->
	<%@ include file="../index/foot.jsp"%>
	<!-- 删除时确认窗口 -->
	<script src="<%=basePath%>statics/ace/js/bootbox.js"></script>
	<!-- ace scripts -->
	<script src="<%=basePath%>statics/ace/js/ace/ace.js"></script>
	<!-- 日期框 -->
	<script src="<%=basePath%>statics/ace/js/date-time/bootstrap-datepicker.js"></script>
	<!-- 下拉框 -->
	<script src="<%=basePath%>statics/ace/js/chosen.jquery.js"></script>
	<!--提示框-->
	<script type="text/javascript" src="<%=basePath%>statics/js/jquery.tips.js"></script>
	</body>

<script type="text/javascript">
$(top.hangge());

//删除
function delObj(pkId,msg){
	bootbox.confirm("确定要删除["+msg+"]吗?", function(result) {
		if(result) {
			var url = "<%=basePath%>${baseInfo.moduleName!''}/${baseInfo.objectName!''}/deleteIds?ids="+pkId+"&tm="+new Date().getTime();
			$.get(url,function(data){
				if("0" == data.errorCode){
					nextPage(${r"${pageDto.currentPage}"});
				}else{
					bootbox.alert(data.errorMsg);
				}
			});
		};
	});
}

//新增
function add(){
	 top.jzts();
	 var diag = new top.Dialog();
	 diag.Drag=true;
	 diag.Title ="新增";
	 diag.URL = '<%=basePath%>${baseInfo.moduleName!''}/${baseInfo.objectName!''}/goAdd';
	 diag.Width = 469;
	 diag.Height = 510;
	 diag.CancelEvent = function(){ //关闭事件
		top.jzts();
		nextPage(${r"${pageDto.currentPage}"});
		diag.close();
	 };
	 diag.show();
}

//修改
function editObj(pkId){
	 top.jzts();
	 var diag = new top.Dialog();
	 diag.Drag=true;
	 diag.Title ="编辑${baseInfo.tableNameRemark!''}";
	 diag.URL = '<%=basePath%>${baseInfo.moduleName!''}/${baseInfo.objectName!''}/goEdit?${baseInfo.primaryKeyProperty!''}='+pkId;
	 diag.Width = 469;
	 diag.Height = 510;
	 diag.CancelEvent = function(){ //关闭事件
		nextPage(${r"${pageDto.currentPage}"});
		diag.close();
	 };
	 diag.show();
}

//导出excel
function toExcel(){
	var url = "<%=basePath%>${baseInfo.moduleName!''}/${baseInfo.objectName!''}/excel";
	$("#searchForm").attr("action",url).submit();
}

//查看
function viewObj(pkId){
	 top.jzts();
	 var diag = new top.Dialog();
	 diag.Drag=true;
	 diag.Title ="查看${baseInfo.tableNameRemark!''}";
	 diag.URL = '<%=basePath%>${baseInfo.moduleName!''}/${baseInfo.objectName!''}/goView?${baseInfo.primaryKeyProperty!''}='+pkId;
	 diag.Width = 469;
	 diag.Height = 380;
	 diag.CancelEvent = function(){ //关闭事件
		diag.close();
	 };
	 diag.show();
}

//批量操作
function makeAll(){
	bootbox.confirm('确定要删除选中的数据吗?', function(result) {
		if(result) {
			var str = '';
			$('input[name="ids"]:checked').each(function(index,item){    
				if(index != 0){
					str = str + "," + $(this).val() ;
				}else{
					str = str + $(this).val();
				}
			}); 
			
			if(str==''){
				bootbox.dialog({
					message: "<span class='bigger-110'>您没有选择任何内容!</span>",
					buttons: 			
					{ "button":{ "label":"确定", "className":"btn-sm btn-success"}}
				});
				$("#zcheckbox").tips({
					side:3,
		            msg:'点这里全选',
		            bg:'#AE81FF',
		            time:2
		        });
				
				return;
			}else{
				$.ajax({
					type: "POST",
					url: '<%=basePath%>${baseInfo.moduleName!''}/${baseInfo.objectName!''}/deleteIds?tm='+new Date().getTime(),
			    	data: {ids:str},
					dataType:'json',
					//beforeSend: validateData,
					cache: false,
					success: function(data){
						if("0" == data.errorCode){
							nextPage(${r"${pageDto.currentPage}"});
						}else{
							bootbox.dialog({
								message: "<span class='bigger-110'>"+ data.errorMsg + "</span>",
								buttons: {"button" :{"label" : "确定","className" : "btn-sm btn-success"}}
							});
						}
					}
				});
			}
		}
	});
}

$(function() {
	//日期框
	$('.date-picker').datepicker({autoclose: true,todayHighlight: true});
	
	//下拉框
	if(!ace.vars['touch']) {
		$('.chosen-select').chosen({allow_single_deselect:true}); 
		$(window)
		.off('resize.chosen')
		.on('resize.chosen', function() {
			$('.chosen-select').each(function() {
				 var $this = $(this);
				 $this.next().css({'width': $this.parent().width()});
			});
		}).trigger('resize.chosen');
		$(document).on('settings.ace.chosen', function(e, event_name, event_val) {
			if(event_name != 'sidebar_collapsed') return;
			$('.chosen-select').each(function() {
				 var $this = $(this);
				 $this.next().css({'width': $this.parent().width()});
			});
		});
		$('#chosen-multiple-style .btn').on('click', function(e){
			var target = $(this).find('input[type=radio]');
			var which = parseInt(target.val());
			if(which == 2) $('#form-field-select-4').addClass('tag-input-style');
			 else $('#form-field-select-4').removeClass('tag-input-style');
		});
	}

	
	//复选框全选控制
	var active_class = 'active';
	$('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function(){
		var th_checked = this.checked;//checkbox inside "TH" table header
		$(this).closest('table').find('tbody > tr').each(function(){
			var row = this;
			if(th_checked) $(row).addClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', true);
			else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', false);
		});
	});
});


//检索
function searchs(){
	top.jzts();
	var url = "<%=basePath%>${baseInfo.moduleName!''}/${baseInfo.objectName!''}/page/listPagination";
	$("#searchForm").attr("action",url).submit();
}

function resets(){
	$(':input','#searchForm').not(':button,:submit,:reset,:hidden').val('').removeAttr('checked').removeAttr('checked');
}

</script>
</html>